from time import sleep
from selenium import webdriver
from  selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import os.path

# 打开浏览器
sleep(2)
driver = webdriver.Chrome()

# 打开网站
sleep(2)
url ='file:///' + os.path.abspath('html') + '/注册A.html'
driver.get(url)

# 定位A账号
sleep(2)
driver.find_element(By.ID,'userA').send_keys('666666')

# 定位A密码
sleep(2)
driver.find_element(By.ID,'passwordA').send_keys('666666')

# 定位电话A
sleep(2)
driver.find_element(By.ID,'telA').send_keys('119')

# 定位邮箱A
sleep(2)
driver.find_element(By.ID,'emailA').send_keys('180680@qq.com')

# 定义城市
sleep(2)
select = driver.find_element(By.ID,'selectA')
select =Select(select)

# option选择
sleep(2)
select.select_by_value('gz')

# 定位弹窗
sleep(2)
alert = driver.find_element(By.XPATH,'//*[@id="alerta"]')
alert.click()

#获取弹窗
sleep(2)
alter = driver.switch_to.alert
alter.accept()  #确定

# 用 xpath 定位注册
sleep(2)
driver.find_element(By.XPATH,'//*[@id="zc"]/fieldset/button').click()

# 关闭浏览器
sleep(5)
driver.quit()
